<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('评分指标项列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>模板名称：</label>
                                <select name="templateId">
                                    <option th:each="pets:${templateList}" th:value="${pets.id}"
                                            th:text="${pets.templateName}" th:field="*{gradeItem.templateId}" ></option>
                                </select>
                            </li>
                            <li>
                                <label>分类：</label>
                                <select name="typeId">
                                    <option value="">所有</option>
                                    <option th:each="pets:${list}" th:value="${pets.typeId}"
                                            th:text="${pets.typeName}"  th:field="*{gradeItem.typeId}"></option>
                                </select>
                            </li>
                            <li>
                                <label>封顶分数：</label>
                                <input type="text" name="maxScore"/>
                            </li>

<!--                            <li>
                                <label>状态：</label>
                                <select name="status" th:with="type=${@dict.getType('sys_normal_disable')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>-->
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="search_tabel();"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:item:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:item:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:item:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
<!--                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:item:export">
                    <i class="fa fa-download"></i> 导出
                </a>-->
            </div>
            <div class="col-sm-12 select-table table-striped">
                <div>
                    <label id="template_name" style="font-weight: bold;"></label>
                </div>
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:item:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:item:remove')}]];
        var prefix = ctx + "system/item";
        var selectedTemplateId = [[${selectedTemplateId}]];
        var selectedTypeId = [[${selectedTypeId}]];

        $(function() {
        $("select[name='templateId']").val(selectedTemplateId);
        $("select[name='typeId']").val(selectedTypeId);
        $("#template_name").html($("select[name='templateId']").find("option:selected").text());

            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add?templateId="+selectedTemplateId+"&typeId="+selectedTypeId,
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "评分指标项",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '指标项ID',
                    visible: false
                },
               /* {
                    field: 'templateName',
                    title: '模板'
                },*/
                {
                    field: 'typeName',
                    title: '分类'
                },
                {
                    field: 'itemContent',
                    title: '评价标准内容'
                },
                {
                    field: 'maxScore',
                    title: '封顶分数'
                },
                {
                    field: 'itemOrder',
                    title: '排序号'
                },
                {
                    field: 'deductFlag',
                    title: '是否可抵扣',
		        	formatter: function (value, row, index) {
		        		return deductFlags(row);
		        	}
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        /* 抵扣状态显示 */
		function deductFlags(row) {
		    if (row.deductFlag == 1) {
    			return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.id + '\')"></i> ';
    		} else {
    			return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.id + '\')"></i> ';
    		}
		}

		/* 抵扣-停用 */
		function disable(id) {
			$.modal.confirm("确认要设置为不可抵扣吗？", function() {
				$.operate.post(prefix + "/changeDeductFlags", { "id": id, "deductFlag": 1 });
		    })
		}

		/* 抵扣启用 */
		function enable(id) {
			$.modal.confirm("确认要设置为可抵扣吗吗？", function() {
				$.operate.post(prefix + "/changeDeductFlags", { "id": id, "deductFlag": 0 });
		    })
		}

        /* 查询 */
        function search_tabel() {
            $.table.search();
            $("#template_name").html($("select[name='templateId']").find("option:selected").text());
        }
    </script>
</body>
</html>